]".
If you use existing ASP.. net. in the above "Hello World" example, we need to use "
After careful observation, we can find that each part of the code in the previous example requires five characters ("
Use razor syntax
In razor, you only need to use the "@" character to mark the beginning of the code block, which is different from the "
The razor
need to use "
After careful observation, we can find that each part of the code in the previous example requires five characters ("
Use razor syntax
In razor, you only need to use the "@" character to mark the beginning of the code block, which is different from the "
The razor analyzer understands the C # Or VB syntax used in the code block-that's
Razor basic syntax 1: Razor basic syntax
Directory:
What is Razor?
Rendering HTML
Razor syntax
Implicit Razor expression
Explicit Razor expression
What is Razor?
First, Razor grammar1. Razor identifierExplanation: The @ character is defined as the identifier of the Razor server code block, followed by the server code. It is a good idea to use @{ String userName = "Kai Super"; span > My name is: @userNamespan> span > My date of birth: @DateTime. Now.tostring ("Yyyy-mm-dd"); span >
block, unlike the "The Razor parser understands the syntax of C # or VB used in blocks of code-that's why we don't need to explicitly shut down blocks of code in the previous example. Razor can automatically recognize that the above statements are separate blocks of code and silently close them for us.Look, even a trivial example like "Hello World" saves us 12 keystrokes. and the "@" character on the
Razor, razor
When learning MVC, you will always see the default Razor when creating a controller:
Then, we can write the following in the created View:
So what are the things with @ That don't look like html but put on The View? Let's start from the beginning ~~
1. What is Razor
existing. ASPX markup syntax, we might write it using
One observation to make about this ' Hello World ' sample is ' that ' each code nugget block requires 5 characters (
Building it with Razor Syntax
You denote the "start of" a code block with Razor using a @ character. Unlike
The Razor parser has semantic knowledge of C#/VB code used within Code-blocks–whi
Razor Exercise 4, razor exercise
Practice Razor's logic processing today. Generally, the following
1. if
2. else
3. else if
4. switch
In the following demonstration, Insus. NET demonstrates 1, 2, and 4 respectively:The xxx. cshtml code is as follows:@ {Layout = null; string laborDay = ""; string name = "Insus. NET "; string [] colors = {" ff0000 "," 0000ff "," 00ff00 "}; // red, blue, green} Animation demo
The key is to output JS on the plain text content, so that the browser to parse the JS code@: Indicates the direct output string afterEither way, note that MVC Razor with JavaScript (embedded razor in JS)
Razor and razorPreface:
The core of the Razor engine is to identify the @ symbol and angle brackets:1. 2. [For more information, see the example below.]
@for (int i = 0; i
{
}
Basic Syntax: Syntax 1 ,@()
Expression
@ (1 = 0? "1 equals 0": "1 not equal to 0 ")
Syntax 2 ,@{}
Statement Block
@{
var now = DateTime.Now;
if (now.Hour.CompareTo(12)
{
}
else
{
}
}
Use ajax to partially update the Razor page and ajax to partially update the razor page
Razor is very powerful, but it cannot be refreshed. Therefore, it must be used with ajax.
This article provides a simple example to achieve local refresh through Razor and ajax.
First, create an MVC Project
Let's create a simple Co
Some methods of link in Razor syntax, razor syntax Link
In Razor, there are HTML. ActionLink and Url. Action to render the link. What are their differences. If you can clearly distinguish them, you will know under what circumstances to use them.First, let's take a look at html. ActionLink. This method loads a lot and generates a If no controller is specified, the
Razor Exercise 2, razor exercise
Razor data types include string, int, float, decimal, and bool.In addition, data type conversion is required. The common methods are as follows:ToString (): converts the data type to string ). This is the same as the C # syntax.IsBool () and AsBool () convert strings to Boolean values ).IsFloat () and AsFloat () convert strings t
Razor Exercise 3, razor exercise
In Razor syntax, it uses three types of material loop processing: for, while, and foreach.
The following Insus. NET illustrates an example in the ASP. net mvc environment by appending the source code:While: Animation demonstration:
Forced conversion of the razor type and forced conversion of the razor type
1. If the background obtains a List type
1. Obtain array data in the background
Var dutyList = IOCFactory. R ViewBag. dutyList = dutyList;
2. Front-end cyclic binding drop-down box
@ Foreach (Object item in ViewBag. dutyList){}
2. If the backend obtains a List
1. Obtain the object array type in the background
List ViewBag. dutyLis
A new view Engine:razor is introduced in ASP.net MVC 3. Using razor does not require learning new languages, it is easier to combine dynamic code with HTML, discard tags like
Type @model webapplication1.models in the first line of the view. There will be smart tips to get it done.
The view of the razor engine is in the cshtml format, and the syntax of the next two scripting engines is compared below, as de
ASP. NET Core Chinese Document Chapter 4 MVC (3.2) Razor syntax reference, mvcrazor
Original article: Razor Syntax ReferenceBy Taylor Mullen and Rick AndersonTranslation: Liu Yi (AlexLEWIS)Proofreader: He zhenghouWhat is Razor?
Razor is a tag syntax that can be converted to web pages based on server code. The
Original: Razor Syntax ReferenceTaylor Mullen, Rick AndersonTranslation: Liu Yi (alexlewis)Proofreading: He ShiodomeWhat is Razor?Razor is a markup syntax that can be converted to a Web page based on server-side code. The Razor syntax consists of Razor tags, C #, and HTML. F
Original article address:
Http://www.cnblogs.com/wbpmrck/archive/2011/10/13/2210338.html
1. Preface
I recently read an old Scott article and thought it was quite good. I tried to translate it,ArticleIt mainly describes how to use the @ helper syntax in razor to define reusable view template methods. If you have any omissions, please kindly advise them ~
Address: http://weblogs.asp.net/scottgu/archive/2011/05/12/asp-net-mvc-3-and-the-h
Validation.isvalid () modified to verify the specific fields such as Validation.isvalid ("account", "password")For example, combination input validationThis is a bit more complicated, because the razor verification mechanism does not have the function of combination verification at present, it needs to be self-expanding in front of the background.Simply put, the original way of using jquery.validate is verified in the front-end for the place where th
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.